/// <reference path="rsseasy.min.js" />

RssEasy.WeiXin = {};
RssEasy.WeiXin.getBrandWCPayRequest = function (data) {
    WeixinJSBridge.invoke('getBrandWCPayRequest', data, function (res) {
        if (res.err_msg === "get_brand_wcpay_request:ok") {
            RssEasy.WeiXin.onGetBrandWCPayRequest(res);
            return;
        }
        alert(res["err_desc"]);
        RssEasy.WeiXin.onGetBrandWCPayRequestFail(res);
    });
};
RssEasy.WeiXin.onGetBrandWCPayRequest = function (res) {
};
RssEasy.WeiXin.onGetBrandWCPayRequestFail = function (res) { }

RssEasy.WeiXin.UnifiedOrder = function (data) {
    $.getJSON("/api/weixin/order.php", data, function (json) {
        RssEasy.WeiXin.onUnifiedOrder(json);
    });
};
RssEasy.WeiXin.Recharge = function (data) {
    data["myid"] = RssUser.Data.myid;
    data["channelid"] = "2";
    data["sourceid"] = "2";
    data["createip"] = "211.159.176.31";
    data["openid"] = RssUser.Data.openid;
    $.getJSON("/api/pay/recharge", data, function (json) {
        RssEasy.WeiXin.onUnifiedOrder(json);
    });
};
RssEasy.WeiXin.onUnifiedOrder = function (json) {

}
RssEasy.WeiXin.onLoginReg = function (json) {

};
RssEasy.WeiXin.Authorize = function () {
    location.href = "/api/weixin/authorize";  //用户转到微信授权登录页面
};

//注册注册登录
RssEasy.WeiXin.LoginReg = function () {
    if (!RssUser.Data.openid && !Url['openid']) {
        RssEasy.WeiXin.Authorize();
        return;
    }
    new Ajax("weixin/login").keyvalue({"openid": RssUser.Data.openid}).getJson(function (data) {
        RssUser.Update(data);
        RssEasy.WeiXin.onLoginReg(data);
    });
}
RssEasy.WeiXin.LoginReg();
new Ajax("weixin/ticket").keyvalue("url", location.href.replace(location.hash, "")).getJson(function (data) {
    data["jsApiList"] = ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone", "startRecord", "stopRecord", "onVoiceRecordEnd", "playVoice", "pauseVoice", "stopVoice", "onVoicePlayEnd", "uploadVoice", "downloadVoice", "chooseImage", "previewImage", "uploadImage", "downloadImage", "translateVoice", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem", "closeWindow", "scanQRCode", "chooseWXPay", "openProductSpecificView", "addCard", "chooseCard", "openCard"];
    wx.config(data);
});